home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / dkbuts.zip / PICKSHEL.C < prev    next >
C/C++ Source or Header  |  1991-05-16  |  2KB  |  64 lines

  1. /*
  2.    Note: This is a clip from Ray Tracing News...
  3.    This was the basis of my shellgen.bas program.
  4.    The output is in generic NFF format, but is easily changed to any other
  5.    script format.
  6.  
  7.  
  8.     A related book that just came out is "Computers, Pattern, Chaos, and
  9. Beauty" by Clifford Pickover (St. Martin's Press).  At first I thought this
  10. was just another fractal book, but there are many other functions and
  11. algorithms explored here.  This book is something like a collection of
  12. "Computer Recreations" columns, and is worth checking out.  One topic mentioned
  13. in the book is creating sea shells by a series of spheres.  This was also
  14. covered in the IEEE CG&A November 1989 article, pages 8-11.  Here's a code
  15. fragment that outputs a series of spheres in NFF (I leave a good view & lights
  16. & colors to you).  Cut the number of steps way down for a rough idea where
  17. the surface is located, and have fun playing with the various numbers and
  18. formulae.
  19.  
  20. DKB - I've changed the format to output a simple DKB script.
  21. */
  22.  
  23. #include <stdio.h>
  24. #include <math.h>
  25.  
  26. #ifndef M_PI
  27. #define M_PI 3.1415926535897932384626
  28. #endif
  29.  
  30. main(argc,argv)
  31. int argc;  char *argv[];
  32. {
  33. static    double    gamma = 1.0 ;    /* 0.01 to 3 */
  34. static    double    alpha = 1.1 ;    /* > 1 */
  35. static    double    beta = -2.0 ;    /* ~ -2 */
  36. static    int    steps = 600 ;    /* ~number of spheres generated */
  37. static    double    a = 0.15 ;    /* exponent constant */
  38. static    double    k = 1.0 ;    /* relative size */
  39. double    r,x,y,z,rad,angle ;
  40. int    i ;
  41.  
  42.     printf ("OBJECT\n   UNION\n");
  43.     for ( i = -steps*2/3; i <= steps/3 ; ++i ) {
  44.     angle = 3.0 * 6.0 * M_PI * (double)i / (double)steps ;
  45.     r = k * exp( a * angle ) ;
  46.     x = r * sin( angle ) ;
  47.     y = r * cos( angle ) ;
  48.     /* alternate formula: z = alpha * angle */
  49.     z = beta * r ;
  50.     rad = r / gamma ;
  51.  
  52.     printf( "      SPHERE <%g %g %g> %g END_SPHERE\n", x, y, z, rad ) ;
  53.     }
  54.     printf ("   END_UNION\n");
  55.     printf ("   TEXTURE\n");
  56.     printf ("      AMBIENT 0.3\n");
  57.     printf ("      DIFFUSE 0.7\n");
  58.     printf ("      PHONG 1.0\n");
  59.     printf ("      COLOUR RED 1.0 GREEN 0.498939 BLUE 0.0 { Coral }");
  60.     printf ("      PHONGSIZE 20.0\n");
  61.     printf ("   END_TEXTURE\n");
  62.     printf ("END_OBJECT\n");
  63. }
  64.